using SharpDX;
using System.Collections.Generic;

namespace Engine.FileFormats3D.WR2TrafficFiles
{
    public class StreetNodeFileBlock
    {
        #region Private Fields

        private List<StreetNode> streetnodes = new List<StreetNode>();

        #endregion Private Fields

        #region Public Constructors

        public StreetNodeFileBlock()
        {
        }

        #endregion Public Constructors

        #region Public Properties

        public List<StreetNode> Streetnodes
        {
            get { return streetnodes; }
            set { streetnodes = value; }
        }

        #endregion Public Properties

        #region Public Methods

        public void AddStreetNode(float positionX, float positionY, float positionZ, float angleSinus, float angleCosinus, float inclination)
        {
            StreetNode streetnode = new StreetNode(Streetnodes.Count, positionX, positionY, positionZ, angleSinus, inclination, angleCosinus, false);
            Streetnodes.Add(streetnode);
        }

        public short Count()
        {
            return (short)Streetnodes.Count;
        }

        public double GetDirectionInDegree(int nodeID)
        {
            if (nodeID <= Streetnodes.Count - 1 && nodeID >= 0)
            {
                return this.Streetnodes[nodeID].GetDirectionInDegree();
            }
            else
            {
                return this.Streetnodes[0].GetDirectionInDegree();
            }
        }

        public int GetNode(Vector3 vector3)
        {
            for (int sn = 0; sn < this.Streetnodes.Count; sn++)
            {
                if (Streetnodes[sn].positionX == vector3.X &&
                Streetnodes[sn].positionY == vector3.Y &&
                Streetnodes[sn].positionZ == vector3.Z)
                {
                    return sn;
                }
            }
            return -1;
        }

        public void Save(System.IO.BinaryWriter bw)
        {
            foreach (StreetNode sn in this.Streetnodes)
            {
                sn.Save(bw);
            }
        }

        #endregion Public Methods
    }
}